
/*
 *  Copyright 2007 Marc Lanctot and Marc Gendron-Bellemare
 *
 *  This file is part of OpenMTG.
 *
 *  OpenMTG is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpenMTG is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OpenMTG.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


import java.util.*;

public class PhaseInfo
{
	public enum Phase { 
      NEWTURN("New turn"), 
      UNTAP("Untap"), 
      UPKEEP("Upkeep"), 
      DRAW("Draw"), 
      PREMAIN("Pre-combat"), 
      COMBAT("Declaring attackers"),
      COMBATINSTANT("Instants"), 
      BLOCK("Declaring blockers"),
  	  BLOCKINSTANT("Instants"), 
      FIRSTDAMAGE("First strike damage"), 
      ASSIGNDAMAGE("Damage assignment"), 
      DAMAGEINSTANT("Instants"), 
      DAMAGE("Damage resolution"), 
      POSTMAIN("Post-combat"), 
  	  DISCARD("Discard"), 
      END("End of turn");
    
      private String aLongName;

      Phase(String pLongName)
      {
        aLongName = pLongName;
      }

      public String longName() { return aLongName; }
    };
	
	private boolean aHasAttacked;
	private boolean aHasPlayedLand;
	private Phase aPhase;
	private boolean aNewPhase;

	public PhaseInfo()
	{
		aPhase = Phase.NEWTURN;
	}

	public void setAttacked(boolean pAttacked)
	{
		aHasAttacked = pAttacked;
	}

	public boolean getAttacked()
	{
		return aHasAttacked;
	}

	public void setPlayedLand(boolean pPlayedLand)
	{
		aHasPlayedLand = pPlayedLand;
	}

	public boolean getPlayedLand()
	{
		return aHasPlayedLand;
	}

	public boolean getNewPhase() { return aNewPhase; }
	public void setNewPhase(boolean pNewPhase) { aNewPhase = pNewPhase; }

	public Phase getPhase()
	{
		return aPhase;
	}

	public Phase nextPhase()
	{
		if (aPhase.equals(Phase.END)) return Phase.END;
		
		// Why isn't there a enum++? someone please fix this to be nicer
		EnumSet set = EnumSet.range(Phase.NEWTURN, Phase.END);
		aPhase = (Phase)set.toArray()[aPhase.ordinal()+1];
		System.err.println ("\tPHASE is now "+aPhase);
		aNewPhase = true;

		return aPhase;
	}

	/** Resets the phase information for the beginning of a new turn.
	  */
	public void newTurn()
	{
		aHasAttacked = false;
		aHasPlayedLand = false;
		aPhase = Phase.NEWTURN;
	}
}

